from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.common.by import By
import time
import threading


class A1:
    def __init__(self, x, y):
        self.x = x
        self.y = y
        return

    def she(self):
        dr = webdriver.Chrome(service=Service('chromedriver.exe'))
        dr.set_window_position(self.x, self.y)
        dr.set_window_size(200, 400)
        dr.implicitly_wait(10)
        dr.get('https://bahuyun.com/bdp/form/1370889698236956672')
        return dr

    def run(self):
        dr = self.she()
        dr.implicitly_wait(10)
        for i in range(2):
            # 单选框
            dr.find_element(By.XPATH, '//*[@id="my-node"]/div[1]/div/div[2]/div/div/div[2]/div/i').click()
            # 多选框
            dr.find_element(By.XPATH, '//*[@id="my-node"]/div[2]/div/div[2]/div/div/div[1]/div/i').click()
            dr.find_element(By.XPATH, '//*[@id="my-node"]/div[2]/div/div[2]/div/div/div[3]/div/i').click()
            # 下拉菜单
            dr.find_element(By.XPATH, '//*[@id="my-node"]/div[3]/div/div[2]/div/div/div/select/option[1]').click()
            # 填写日期
            dr.find_element(By.XPATH, '//*[@id="input-YvRQ32wsVyUFlGRoRBio7"]').send_keys('0020220101')
            # 评价
            dr.find_element(By.XPATH, '//*[@id="my-node"]/div[5]/div/div[2]/div/div[1]/div[2]/div[4]/i').click()
            dr.find_element(By.XPATH, '//*[@id="my-node"]/div[5]/div/div[2]/div/div[2]/div[2]/div[5]').click()
            # 上传附件，上传图片的路径必须是绝对路径
            dr.find_element(By.XPATH, '//*[@id="my-node"]/div[6]/div/div[2]/div/div/div/div/div/input').send_keys(
                'C:\\Users\\Administrator\\Desktop\\报告\\图片\\1.jpg')
            # 提交
            dr.find_element(By.XPATH, '//*[@id="submit-button"]').click()
            # 在填写一次
            dr.find_element(By.XPATH, '//*[@id="app"]/div/div/div[1]/div[2]/div[3]/button').click()
            # 获取全部标签页的句柄
            handles = dr.window_handles
            print(handles)
            time.sleep(2)
            # 关闭之前控制的标签页
            dr.close()
            # 通过句柄切换标签页
            time.sleep(2)
            dr.switch_to.window(handles[1])
            # 获取当前标签页句柄
            dr2 = dr.current_window_handle
            print(dr2)
        time.sleep(23)


a1 = A1(0, 0)
a2 = A1(800, 0)
a3 = A1(0, 500)
a4 = A1(800, 500)

threading.Thread(target=a1.run).start()
threading.Thread(target=a2.run).start()
threading.Thread(target=a3.run).start()
threading.Thread(target=a4.run).start()
